package com.web.controller;

import com.web.bean.PageModel;
import com.web.bean.学生情况;
import com.web.dao.学生情况Dao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;


@WebServlet("/getAllStudent")
public class StudentQueryController extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        String pageNo = req.getParameter("pageNo");
        String search = req.getParameter("search");
        if(search == null){
            search = "";
        }
        int pageNum = 1;
        if (pageNo != null && !pageNo.equals("")) {
            pageNum = Integer.parseInt(pageNo);
        }
        学生情况Dao dao = new 学生情况Dao();
        PageModel page = new PageModel(pageNum, dao.queryStudentCount(search));
        List<学生情况> list = dao.queryStu(search,page);
        req.setAttribute("list", list);
        req.setAttribute("pageInfo", page);
        req.setAttribute("search", search);
        req.getRequestDispatcher("/StudentIndex.jsp").forward(req, resp);
    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}